let hello: String = '我又来了'
console.log(hello)

function add2(n1: number, n2: number) {
    return n1 + n2
}
console.log(add2(1, 2))
let total: number = 0

let list1: number[] = [1, 2, 3]
let list2: Array<number> = [1, 2, 3]
let list3 = [1, 2, 3]
let person1: [number, string] //元组  Tupple
person1 = [1, '2']

// 联合(Union)类型
let union: string | number
//字面量(Literal类型 
let literal: 1 | 2 | 3
literal = 3
console.log(literal)
// 枚举
enum Color{
    blue=2,
    green,
    red
}
let color=Color.blue
console.log(color)
// any与unknow类型
let randomValue:any=666
randomValue='444'
randomValue={}
console.log(randomValue)

//void undefined 与never

function whileLoop():never{
    while(true){
        console.log('哈哈哈')
    }
}
// whileLoop() //死循环

// 类型适配(类型断言)

// let message:any;
// message='abc'
// message.endWith('c');
// let ddd=(<string>message).endsWith('c')

// 函数类型
let log3=(message:string,code?:number)=>{
    console.log(message,code) //hello undefined
}
log3('hello') 
let log2=(message:string,code:number=0)=>{ //可设置默认值
    console.log(message,code) //hello undefined
}
log2('hello') 
log2('hello',3) 